﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

public struct PatientInfo
{
    public string PName;
    public int Age;
    public string Sex;
    public string DName;
    public string Bp;
    public string HCount;
    public string HRate;
    public string Pid;
}

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]




public class PatientViewWS : System.Web.Services.WebService
{
   private PatientInfo pinfo;

   public PatientViewWS()
   {

        pinfo.Age = 0;
        pinfo.Bp = "";
        pinfo.DName = "";
        pinfo.HCount = "";
        pinfo.HRate = "";
        pinfo.PName = "";
        pinfo.Sex = "";
        pinfo.Pid = "";
    }

    private void AssignValues(string Pid)
    {

        SqlConnection conn = null;
        SqlDataReader rdr = null;

        try
        {
            conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDbConn2"].ToString());
            //Server=localhost;DataBase=PatientRecord;Integrated Security=SSPI");
            conn.Open();


            SqlCommand cmd = new SqlCommand("patientinfo", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@Pid", Pid));

            rdr = cmd.ExecuteReader();
            if (rdr.Read())
            {

                pinfo.PName = rdr.GetString(0);
                pinfo.Age = rdr.GetInt32(1);
                pinfo.Sex = rdr.GetString(2);
                pinfo.DName = rdr.GetString(3);
                pinfo.Bp = rdr.GetString(4);
                pinfo.HCount = rdr.GetString(5);
                pinfo.HRate = rdr.GetString(6);

            }

        }

        finally
        {
            if (conn != null)
            {
                conn.Close();
            }
            if (rdr != null)
            {
                rdr.Close();
            }

        }


    }

    [WebMethod]
    public PatientInfo GetPatientInfo(string pid)
    {
        AssignValues(pid);
        PatientInfo PatientDetails = new PatientInfo();

        PatientDetails.Age = pinfo.Age;
        PatientDetails.Bp = pinfo.Bp;
        PatientDetails.DName = pinfo.DName;
        PatientDetails.HCount = pinfo.HCount;
        PatientDetails.HRate = pinfo.HRate;
        PatientDetails.PName = pinfo.PName;
        PatientDetails.Sex = pinfo.Sex;

        return PatientDetails;

    }

    
}
